From: Álvaro Fernández Rojas Date: Fri, 14 Nov 2025 07:19:17 +0000 (+0100) Subject: src: add fallthrough attribute X-Git-Url: http://git.openwrt.org/%22https:/collectd.org//%22%24PHP_SELF/%22https:/collectd.org/%22%24PHP_SELF?a=commitdiff_plain;h=38a31eb29a48da6c219cbbe49df30e36dba1d5db;p=project%2Fodhcp6c.git src: add fallthrough attribute - Enable fallthrough warnings. - Use fallthrough attribute instead of comments. Signed-off-by: Álvaro Fernández Rojas Link: https://github.com/openwrt/odhcp6c/pull/120 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 9067819..ebbe69b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ target_compile_options(${PROJECT_NAME} PRIVATE -Werror=implicit-function-declara target_compile_options(${PROJECT_NAME} PRIVATE -Wformat) target_compile_options(${PROJECT_NAME} PRIVATE -Werror=format-security) target_compile_options(${PROJECT_NAME} PRIVATE -Werror=format-nonliteral) +target_compile_options(${PROJECT_NAME} PRIVATE -Wimplicit-fallthrough=5) target_compile_options(${PROJECT_NAME} PRIVATE -Wno-unused-parameter) target_compile_options(${PROJECT_NAME} PRIVATE -Wmissing-declarations) diff --git a/src/dhcpv6.c b/src/dhcpv6.c index 7bcaee0..7f73699 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -1144,11 +1144,11 @@ static int dhcpv6_handle_reconfigure(enum dhcpv6_msg orig, const int rc, case DHCPV6_MSG_REBIND: if (t2 != UINT32_MAX) t2 = 0; - // Fall through + _o_fallthrough; case DHCPV6_MSG_RENEW: if (t1 != UINT32_MAX) t1 = 0; - // Fall through + _o_fallthrough; case DHCPV6_MSG_INFO_REQ: msg = odata[0]; syslog(LOG_NOTICE, "Need to respond with %s in reply to %s", @@ -2146,7 +2146,7 @@ int dhcpv6_send_request(enum dhcpv6_msg type) default: syslog(LOG_NOTICE, "Send %s message (elapsed %"PRIu64"ms, rc %d)", retx->name, elapsed, retx->rc); - // Fall through + _o_fallthrough; case DHCPV6_MSG_SOLICIT: case DHCPV6_MSG_INFO_REQ: dhcpv6_send(type, retx->tr_id, elapsed / 10); diff --git a/src/odhcp6c.h b/src/odhcp6c.h index 02578cc..42c645d 100644 --- a/src/odhcp6c.h +++ b/src/odhcp6c.h @@ -24,6 +24,10 @@ #define _o_aligned(n) __attribute__((aligned(n))) #endif /* _o_aligned */ +#ifndef _o_fallthrough +#define _o_fallthrough __attribute__((__fallthrough__)) +#endif /* _o_fallthrough */ + #ifndef _o_packed #define _o_packed __attribute__((packed)) #endif /* _o_packed */